<!-- 页面用户程序打开的环境检测 -->
<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<button aria-role="button" v-if="btnShow" @click="tohome">立即进入</button>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<button aria-role="button" v-if="btnShow" @click="tohome">立即进入</button>
		<!-- #endif -->
		<swiper class="screen-swiper" :style="{height:imgHeight}" :indicator-dots="false" :circular="false"
		 :autoplay="false" interval="5000" duration="500">
			<swiper-item v-for="(item,index) in img_list" :key="index">
				<image aria-role="img" :aria-label="item.label" mode="scaleToFill" :src="item.image"></image>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
	import { mapMutations } from 'vuex';
	export default {
		data() {
			return {
				img_list: [
					{
						image: '/static/hb1.jpg',
						label: '杭@在线，@“爱的”中文发音，这是一个关于爱的平台，对接万千爱心资源，杭@在线，打造有爱无碍平台。'
					},
					{
						image: '/static/hb2.jpg',
						label: '@移动互联网的标识符，这是一个用智能化技术打造的爱的平台，杭@在线，城市大脑，让助残扶残政策像阳光雨露一样洒向每位残疾人。'
					},
					{
						image: '/static/hb3.jpg',
						label: '杭@在线，@就是呼唤。这是一个你可以随时@我的爱的平台，我们愿意倾听响应，每位残障朋友对爱的呼唤。'
					}
					
				],
				btnShow: false,
				users: {state:'0'},
				session: {code: null, skey: null },
			}
		},
		onLoad() {
			let users = uni.getStorageSync('users') || '';
			//this.valid_login(token); //token存在且合法
		},
		onShow() {
			let token = uni.getStorageSync('token') || '';
			this.valid_login(token); //token存在且合法
			
		},
		computed:{
			imgHeight() {
				return this.screenHeight + 'px'
			}
		},
		methods: {
			...mapMutations(['login']),
			valid_login(token) {
				uni.showLoading({title:"加载中"});
				if (token == '') {
					this.btnShow = true
					uni.hideLoading();
					return;
				}
				//请求后台校验
				this.$request.postForm("/view/users/valid").then(res => {
					if (res.data == true) {
						uni.getStorage({key: 'users', success: (res) => {this.login(res.data);}});
						uni.hideLoading();
						uni.switchTab({url: '/pages/admin/vhome'});
						return;
					} else {
						uni.hideLoading();
						this.btnShow = true
					}
				});
			},
			
			tohome() {
				let _this = this;
				uni.showLoading({title:"正在跳转中..."});
				var params = {"authType": 'MP-WEIXIN'};
				this.$request.postForm('/view/users/login', params).then(
					res => {
						_this.users.state = res.data.users.state;
						_this.users.citizenName = res.data.users.citizenName;
						_this.users.uid = res.data.users.uid;
						_this.users.citizenId = res.data.users.citizenId;
						_this.users.stateId = res.data.users.stateId;
						_this.users.phone = res.data.users.phone;
						_this.users.citizenType = res.data.users.citizenType;
						_this.$store.commit('login', _this.users);
						uni.setStorageSync('token', res.data.token);
						uni.hideLoading();
						//成功登录后跳转首页
						uni.switchTab({
							url: '/pages/admin/vhome',
							success: (res) => {
								let page = getCurrentPages().pop(); //当前页面
								if (page == undefined || page == null) return; 
								page.onLoad();
							 }
						});
						uni.navigateBack()
					},
					err => {
						console.log(err);
					}
				);
			},
			
			
		}
	}
</script>

<style>
	page {
		background: #fff;
	}
	.picture-preview-big {
		width: 100%;
		height: 100%;
	}
	button{
		background: rgba(232,89,22,1);
		z-index: 999999999999;
		position: absolute;
		right:24rpx;
		bottom: 24rpx;
		border-radius: 100rpx;
		font-size: 24rpx !important;
		color: #FFF;
	}
	button:after{
		border: 0 !important;
	}
</style>
